package distributed_lock

import (
	"context"
	"time"
)

const (
	// DefaultExpiration redis锁默认过期时间
	DefaultExpiration = 5 * time.Second
	// DefaultRetryDelayTimes 每次重新获取锁的默认间隔时间
	DefaultRetryDelayTimes = 100 * time.Millisecond
)

type DistributedLock interface {
	// TryLock 尝试获得锁
	// key : 锁的key
	// expireTime : 锁的过期时间
	// waitTime : 等待获取锁的超时时间
	TryLock(ctx context.Context, key string, expireTime, waitTime time.Duration) (bool, error)
	// UnLock 释放锁
	UnLock(ctx context.Context, key string) (bool, error)
	// RefreshLock 更新锁，存在则更新过期时间，不存在则创建key
	RefreshLock(ctx context.Context, key string, expireTime time.Duration) (bool, error)
}
